//
// Created by wxd on 2025/9/11.
//


#include "Material.h"

void Material::bind() {
    if (mShader) {
        mShader->bindProgram();
    }
}

void Material::unbind() {
    if (mShader) {
        mShader->unbindProgram();
    }
}

void Material::loadShader(const std::string &vertPath, const std::string &fragPath) {
    mShader = std::make_unique<Shader>(vertPath, fragPath);
}

void Material::uniform(const std::string &name, const UniformValue &value) {
    if (!mShader) {
        return;
    }

    std::visit([&](auto&& arg) {
            using T = std::decay_t<decltype(arg)>;

            mShader->setUniform(name, arg);
        }, value);
}

void Material::uniforms(const std::unordered_map<std::string, UniformValue> &values) {
    for (const auto& [name, value] : values) {
        uniform(name, value);
    }
}

